<link href="__PUBLIC__/css/page.css" rel="stylesheet"  type="text/css" />
<div class="pd-20">
	<a class="btn btn-success" onclick="showFood('新增一期','{:U("Admin/Order/addPeriod")}','4','500',300)">添加期数</a>
    <if condition="$periods eq null ">
        <div class="row">没有期数</div>
        <else />
        <div class="mt-20">
        	
            <table class="table table-border table-bordered table-bg table-sort table-striped">
                <thead>
                    <tr class="text-c">
                        <th width="30">期数</th>
                        <th width="30">期数名称</th>
                        <th width="80">开始时间</th>
                        <th width="80">结束时间</th>
                        <th width="40">状态</th>
                        <th width="50">操作</th>
                    </tr>
                </thead>
                <!--{$vo.postcode}-->
                <tbody>
                    <volist name="periods" id="period" key="k">
                        <tr class="text-c">
                            <td>{$period.pname}</td>
                            <td>{$period.ppname}</td>
                            <td>{$period.fromtime|date="Y-m-d H:i:s",###}</td>
                            <td>{$period.endtime|date="Y-m-d H:i:s",###}</td>
                            <td>
                            	<if condition='$period.status eq 0'>未开启<elseif condition="$period.status eq 1"/>准备<elseif condition="$period.status eq 2"/>进行中<elseif condition="$period.status eq 3"/>已结束</if>
								<egt name='period.status' value='2'>
                            	<if condition='$period.dosendmsg eq 1'>| 已群发<else/>| 未群发</if>
                            	</egt>
                            </td>
                            <td>
                            	<if condition="$period.status eq 0">
                            	<a class="btn btn-success" onclick="showFood('修改期数','{:U("Admin/Order/addPeriod", array("periodid" =>$period["periodid"]))}','4','500',350)">修改</a>
                            	</if>
                            	<!-- 如果当前有一期在使用中（准备|进行）的，那就只能开启 -->
                            	<if condition="$using eq true">
	                            	<if condition="$period.status eq 1">
									<!-- <a class="btn btn-success" onclick="showOpenMsg({$period['periodid']})" style="background-color:#EA447D;border-color:#EA447D;">开启</a> -->
									<a class="btn btn-success" href="{:U("Admin/Order/bindPeriods", array("periodid" =>$period["periodid"]))}" style="background-color:#EA447D;border-color:#EA447D;">开启</a>
	                            	</if>
                            	<else/>
	                            	<if condition="$period.status eq 0">
	                            	<a class="btn btn-success" onclick="showReadyMsg({$period['periodid']})">准备</a>
                            		</if>
								</if>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
        </div>
    </if>
    <div class="row cl dataTables_wrapper" id="upage">
        {$page}
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
<script>
//用户-编辑
function showFood(title, url, id, w, h) {
    layer_show(title, url, w, h);
}

function change(obj) {
	window.location.href="/index.php?g=Admin&m=Order&a=showAll&state="+$(obj).val();
}
function showReadyMsg(pid) {
	layer.confirm('确定这期吗？确定完后去配置当期套餐、备选、另购的菜品，再开启这期！', {
		btn: ['确定', '取消']
	}, function() {
		$.ajax({
			url: "{:U('Admin/Order/readyPeriod')}",
			data: {
				periodid: pid,
			},
			type: 'post',
			dataType: 'json',
			success: function(data) {
				layer.msg(data.result, function(){
					window.location.href = '{:U("Admin/Order/showPeriods")}';
				});
			},
			error: function() {
				layer.msg('更新出错，请检查！', {icon: 1});
			}
		});
	}, function() {
		
	});
}
// function showOpenMsg(pid) {
// 	layer.confirm('请确定当期 套餐 会员已经配置完成！<br/>会员分组：{$cur_group['grpname']}<br/>套餐菜品：{$cbpfoods_str}<br/>备选菜品：{$opfoods_str}', {
// 		btn: ['确定', '取消']
// 	}, function() {
// 		$.ajax({
// 			url: "{:U('Admin/Order/openPeriod')}",
// 			data: {
// 				periodid: pid,
// 			},
// 			type: 'post',
// 			dataType: 'json',
// 			success: function(data) {  
// 				layer.msg(data.result, function(){
// 					window.location.href = '{:U("Admin/Order/showPeriods")}';
// 				});
// 			},
// 			error: function() {
// 				layer.msg('更新出错，请检查！', {icon: 1});
// 			}
// 		});
// 	}, function() {
		
// 	});
// }


</script>
